package hlp.servlet;

import hlp.bo.PostManager;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PostServlet extends HttpServlet {

	private static final long	serialVersionUID	= 1L;

	public void init(ServletConfig conf) throws ServletException {
		super.init(conf);
	}


	
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		
		String user = req.getParameter("user");
		String userDescription = req.getParameter("userDescription");
		String text = req.getParameter("text");
		
		PostManager postManager = new PostManager();
		postManager.savePost(user, userDescription, text);
		
		
		List listPosts = postManager.getPosts();
		
		System.out.println(listPosts.size());
		
		req.setAttribute("listPosts", listPosts);
		
		res.sendRedirect("index.jsp");
		
	}
	
}
